- /* slfllsub.cpp by K.Tsuru */
- // function ID = 208 DRADIX, BRADIX
- /*************************************************************
- SLong and SInteger classes
- m - n ( m and n have the same sign, and |m|>|n|>0).
- *************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- static const char* const func = "\'-\' or LLSub";
- SLong LLSub(const SLong& m, const SLong& n) {
- if( m.Sign() != n.Sign() ) m.SetError(m.SYNTAX_ERR, func, 208);
- SLong result(m); // result = m
-
- if( (n.aHead > 0) && ( m.Radix() != n.Radix() ) ){
- m.SetError(m.RADIX_ERR, func, 208);
- }
-
- int k = 0;
- long rdx = (long)m.Radix();
- long w;
- const fType* mv = m.ReadFigures();
- const fType* nv = n.ReadFigures();
- fType* rv = result.figure.Elements(); //*
- // Here, result = m.
- uint i;
- for(i = n.aTail; i <= n.aHead ; i++){
- w = (long)mv[i] - (long)nv[i] + k; // -radix <= w < radix
- if( w < 0 ) { k = -1; w += rdx;
- } else k = 0;
- rv[i] = (fType)w;
- }
- for( ; k && (i<= m.aHead); i++){
- //Here nv[i] = 0.
- w = (long)mv[i] + k;
- if( w < 0 ) { k = -1; w += rdx;
- } else k = 0;
- rv[i] = (fType)w;
- }
- if(k) m.SetError(m.SYNTAX_ERR, func, 208);
- //It gets the figure position.
- uint rh = m.aHead, rt = min(m.Tail(), n.Tail()); // aTail --> Tail() since ver 2.191
- #ifndef NDEBUG
- result.figure(rh);
- #endif
- while(!rv[rh]) rh--;
- while(!rv[rt]) rt++;
- result.aHead = rh;
- result.aTail = rt;
- result.SetSign(m.Sign());
- result.DoCutDown(); //It reduces the size if possible.
-
- return result;
- }
slfllsub.cpp : last modifiled at 2017/03/13 14:32:00(1,588 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).